<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="/resource/css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap.min.js"></script>

<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	<div>
	<button type="button" onclick="dels()">批量删除</button>
	<button type="button" onclick="add()">   添  加</button>
	
	</div>
	<table class="table ">
	<tr>
	<td>id</td>
	<td>名称</td>
	<td>规格选项</td>
	<td>操作</td>
	
	</tr>
	<c:forEach items="${info.list }" var="s">
	<tr>
	
	<td>
	<input type="checkbox" name="ck" value="${s.id }">
	${s.id }</td>
	<td>${s.specName }</td>
	<td>
	<c:forEach items="${s.optionList }" var="o">
	${o.optionName }&nbsp;&nbsp;
	</c:forEach>
	
	</td>
	<td>
	<button type="button" onclick="update(${s.id })">修改</button>
	<button type="button" onclick="del(${s.id })">删除</button>
	
	</td>
	
	</tr>
	
	</c:forEach>
	
	</table>
	<jsp:include page="/WEB-INF/view/common/pages.jsp"></jsp:include>
	<script type="text/javascript">
	function goPage(pageNum){
		var url="/spec/list?pageNum="+pageNum;
		$("#workArea").load(url);//发送请求
	}
	function dels(){
		var ids=new Array();
		$("[name='ck']:checked").each(function(i){
			ids[i]=$(this).val();
		})
		alert(ids)
		if(ids.length==0){
			alert("请至少选择一个")
			return;
		}
		var reg=confirm("确定要删除吗");
		if(reg){
			$.post("spec/dels",{ids:ids},function(flag){
				if(flag){
					alert("删除成功")
					var url="/spec/list";
					$("#workArea").load(url);
				}
			})
		}
	}
	function add(){
		var url="/spec/add";
		$("#workArea").load(url);
	}
	function del(id){
		if(confirm("确定要删除吗")){
			$.post("spec/del",{id:id},function(flag){
				if(flag){
					alert("删除成功")
					var url="/spec/list";
					$("#workArea").load(url);
				}else{
					alert("删除失败")
				}
			})
		}
	}
	function update(id){
		url="spec/update?id="+id;
		$("#workArea").load(url);
		
	}
	</script>
</body>
</html>